package cn.xingzhe.monster.user.infrastructure.service;

import cn.xingzhe.monster.user.domain.enums.CaptchaTypeEnum;
import cn.xingzhe.monster.user.domain.service.SmsSender;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * 短信发送服务实现
 * TODO: 实现短信发送功能，集成第三方短信服务
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
@Component
public class SpringSmsSender implements SmsSender {

    private static final Pattern PHONE_PATTERN = Pattern.compile("^1[3-9]\\d{9}$");

    @Override
    public void sendSms(String phone, String content) {
        // TODO: 实现短信发送逻辑
        // 这里可以集成阿里云短信、腾讯云短信等第三方服务
        System.out.println("TODO: 发送短信到 " + phone + ", 内容: " + content);
    }

    @Override
    public void sendRegisterCaptcha(String recipient, String code) {
        sendSms(recipient, "您的注册验证码是：" + code + "，有效期为5分钟，请勿泄露给他人。");
    }

    @Override
    public void sendLoginCaptcha(String recipient, String code) {
        sendSms(recipient, "您的登录验证码是：" + code + "，有效期为5分钟，请勿泄露给他人。");
    }

    @Override
    public boolean supports(String recipient) {
        return PHONE_PATTERN.matcher(recipient).matches();
    }
}

